package com.zjc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zjc.mapper.StuRoomMapper;
import com.zjc.pojo.StuRoom;
import com.zjc.pojo.Student;
import com.zjc.mapper.StudentMapper;
import com.zjc.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 周佳成
 * @since 2023-09-17
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

	@Resource
	StudentMapper studentMapper;
	@Resource
	StuRoomMapper stuRoomMapper;
	@Override
	public boolean isRoomExists(Integer roomid) {

		LambdaQueryWrapper<StuRoom> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.eq(StuRoom::getRoomId,roomid);
		StuRoom room = stuRoomMapper.selectOne(lambdaQueryWrapper);

		return room!=null;
	}

	@Override
	public boolean isStuExists(Integer id) {
		LambdaQueryWrapper<Student> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.eq(Student::getStuId,id);
		Student stu = studentMapper.selectOne(lambdaQueryWrapper);
		return stu!=null;
	}

	@Override
	public int deleteStu(Integer id) {
		LambdaQueryWrapper<Student> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.eq(Student::getStuId,id);
		return studentMapper.delete(lambdaQueryWrapper);
	}

}
